package com.ceba.test.modules.storage.entity;

import java.io.File;

import com.ceba.base.web.entity.IBase;
import com.ceba.test.base.enums.StorageStatusEnum;
import org.apache.commons.lang.StringUtils;


import abc.ID;

/**
 * 文件存储地址表
 * @author wuhaihua

 */
public class GStorageAddress extends IBase {

	private String id;			//ID--关键字
	private String name;		//名称
	private String filter;		//过滤路径
	private String path;		//磁盘路径
	private long capacity;		//磁盘总大小，单位M
	private long actualSize;	//磁盘已经使用大小，单位M
	private long rest;			//磁盘剩余大小，单位M
	private String copyFlag;	//是否拷贝  1 为拷贝  2 已拷贝  默认 1  CopyFlagEnum
	private String status;		//状态 1 未开启 2可用  3已满 默认1		StorageStatusEnum
	
	//---------------------------一下字段非数据库查询字段--------------------------------------
	private String sreachContent;//查询
	public static final String FILTER_PREFIX_FLAG="fileVisit";
	public static final int GUID_LENGT=ID.getGuid().length();
	public static final int FILTER_PREFIX_FLAG_LENGT=FILTER_PREFIX_FLAG.length()+1;
	private File file;
	
	
	public String getSreachContent() {
		return sreachContent;
	}
	public void setSreachContent(String sreachContent) {
		this.sreachContent = sreachContent;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getFilter() {
		return filter;
	}
	public void setFilter(String filter) {
		this.filter = filter;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public long getCapacity() {
		return capacity;
	}
	public void setCapacity(long capacity) {
		this.capacity = capacity;
	}
	public long getActualSize() {
		return actualSize;
	}
	public void setActualSize(long actualSize) {
		this.actualSize = actualSize;
	}
	public long getRest() {
		return rest;
	}
	public void setRest(long rest) {
		this.rest = rest;
	}
	public String getCopyFlag() {
		return copyFlag;
	}
	public void setCopyFlag(String copyFlag) {
		this.copyFlag = copyFlag;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getStatusLanguage(){
		return StorageStatusEnum.getLanguageStr(this.status);
	}
	public static String filterCreateRule(String id) {
		if(StringUtils.isNotEmpty(id)){
			return FILTER_PREFIX_FLAG+"/"+id;
		}
		return null;
	}
	
	/**
	 * 取得存储ID
	 * @param path fileVisit/存储Id/......
	 * @return
	 */
	public static String filterGetStorageAddressId(String path){
		if(StringUtils.isNotEmpty(path)){
			return path.substring(FILTER_PREFIX_FLAG_LENGT, FILTER_PREFIX_FLAG_LENGT+GUID_LENGT);
		}
		return null;
	}


	/**
	 * 取得拦截器的长度
	 * @return  fileVisit/存储Id  的长度
	 */
	public static int getFilterLength(){
		return FILTER_PREFIX_FLAG_LENGT+GUID_LENGT;
	}
	
	public String getFilterStr(){
		if(StringUtils.isNotEmpty(this.id)){
			return filterCreateRule(this.id);
		}
		return null;
	}
	
	/**
	 * 取得path对应的文件对象
	 * @return
	 */
	public File getFile(){
		if(this.file == null){
			this.file=new File(this.path);
		}
		return this.file;
	}
	
}
